import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import RealTime from '../components/situation/RealTime.vue'
import UserQuery from '../components/user/UserQuery.vue'
import ClubCard from '../components/user/ClubCard.vue'
import UserLevel from '../components/user/UserLevel.vue'
import Coupons from '../components/marketing/Coupons.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/home/realTime',
    children: [
      //概况
      {
        path: 'realTime',
        component: RealTime,
      },
      //会员管理
      {
        path: 'userQuery',
        component: UserQuery,
      },
      {
        path: 'clubCard',
        component: ClubCard
      },
      {
        path: 'userLevel',
        component: UserLevel
      },
      //订单管理
      {
        path:''
      }
      //营销
      {
        path: 'coupons',
        component: Coupons
      }

      //数据分析

      //设置
    ]
  },
]

const router = new VueRouter({
  routes
})

//设置路由守卫
router.beforeEach((to, form, next) => {
  if (to.path === '/login') {
    next()
  }
  const tokenStr = window.sessionStorage.getItem('token')
  if (tokenStr) {
    next()
  } else {
    return next('/login')
  }
})

export default router
